package Controller.Employee;

import Service.EmployeeService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;

/*
* 分页页面显示员工信息
* */
@WebServlet(name = "listEmployee", value = "/ListEmployee")
public class ListEmployee extends HttpServlet {
    private EmployeeService employeeService = new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收pageNum
        String pageNum=request.getParameter("pageNum");
        try {
            //创建Map对象，存放查询结果
            Map<String,Object> map=employeeService.selectEmployeeByPage(pageNum==null?1:Integer.valueOf(pageNum));
            //存放查询结果到request域中
            request.setAttribute("map",map);
            //转发到employeeList.jsp页面
            request.getRequestDispatcher("/ListEmployee.jsp").forward(request,response);
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
